﻿using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
using Yoozoo.Gameplay.Liberty.AI.Utils;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty/Car")]
    public class FindNearestCarDestination : CarBaseNode
    {

        public BBParameter<PointDirection> pointDirection = PointDirection.Forward;

        protected override void OnExecute()
        {
            var point = LibertyAIUtils.TrafficManager.PathManager.GetNearestPointByArea(
                _carEntity.position, _carEntity.forward, PathType.Car, pointDirection.value);
            if (point == null)
            {
                EndAction(false);
                return;
            }
            _data.pathId = point.pathId;
            _data.pathPointIndex = point.pointIndex;
            _carEntity.SetDestination(point.position,false);
            EndAction();
        }
    }
}